<?php
class template_listing extends theme
{
	
	protected function head()
	{
	?>
<script type="text/javascript" language="javascript" src="js/jquery.validate.pack.js"></script>

<link type="text/css" rel="stylesheet" href="templates/message/css/listing.css">
<script type="text/javascript" language="javascript" src="templates/message/js/listing.js"></script>
	<?php
	}

	protected function center()
	{
$my = bone::get_user();
		?>
<div class="center-title"><?php echo $this->title; ?></div>
<div class="center-content">

<div class="messages">

<ul>
<?php
$messages = $this->get('messages');

if(count($messages))
{
foreach($messages as $message)
{
?>
<li id="li-<?php echo $message->id; ?>">

<div class="creater">
	<div class="avatar"><?php echo is_null($message->user)?'<img src="storage/avatar/0.jpg" />':'<img src="storage/avatar/'.$message->user->avatar.'" />'; ?></div>
	<div class="name"><?php echo is_null($message->user)?$message->name:$message->user->name; ?></div>
</div>

<div class="message">
	<div class="body">
		<div class="title">
		<?php echo $message->title; ?>
		<?php if(!$my->guest && ($my->id==$message->user_id || $my->is_admin) ){ ?> &nbsp;
		<a href="javascript:;" onclick="javascript:deleteMessage(<?php echo $message->id; ?>);">删除留言?</a>
		<?php } ?>
		</div>
		<div class="time"><?php echo date('Y-m-d H:i',$message->create_time); ?></div>
	</div>
	<div class="bottom"></div>
	
		
	<?php if(!is_null($message->manager)){ ?>
	<div class="reply" id="reply-<?php echo $message->id; ?>">
		<div class="reply-title"><?php echo $message->manager->name.' 回复:'; ?></div>
		<div class="reply-body">
		<?php echo $message->reply; ?>
		<?php if(!$my->guest && ($my->id==$message->manager_id || $my->is_admin) ){ ?> &nbsp;
		<a href="javascript:;" onclick="javascript:deleteReply(<?php echo $message->id; ?>);">删除回复?</a>
		<?php } ?>
		</div>
	</div>
	<?php }else if(!$my->guest && $my->id!=$message->user_id && ($my->is_admin || $my->is_developer)){ ?>
	
	<div class="reply">
		<a href="javascript:" onclick="javascript:jQuery(this).next().show();jQuery(this).remove();">点击回复</a>
		<div class="hide">
			<div class="reply-title" id="reply-title-<?php echo $message->id; ?>">请输入回复:</div>
			<div class="reply-body" id="reply-body-<?php echo $message->id; ?>">
				<textarea id="textarea-reply-<?php echo $message->id; ?>" style="width:100%; height:50px;"></textarea><br />
				<input type="button" value="回复" onclick="javascript:saveReply(<?php echo $message->id; ?>);" />	
			</div>
		</div>
	</div>
	<?php } ?>
</div>

<div class="clr"></div>

</li>
<?php
}
}
else
{
	echo '<li>暂无记录</li>';
}
?>
</ul>

</div>

<p class="align-center"><?php $this->pagination(); ?></p>

</div>


<div class="center-title">发表新留言</div>
<div class="center-content">

<?php $this->message();?>

<form id="form-message">
<table class="edit-table" width="80%">
<?php
$my = bone::get_user();

if($my->guest)
{
?>
<tr>
<td class="key">姓名</td>
<td>
<input type="hidden" name="user_id" id="user_id" value="0" />
<input type="text" name="name" id="name" style="width:120px;" maxlength="30" />
</td>
</tr>
<tr>
<td class="key">邮箱<br><small>(填写后自动接收回复)</small></td>
<td>
<input type="text" name="email" id="email" style="width:200px;" maxlength="30" />
</td>
</tr>
<?php
}
else
{
?>
<input type="hidden" name="user_id" id="user_id" value="<?php echo $my->id; ?>" />
<input type="hidden" name="name" id="name" value="<?php echo $my->name; ?>" />
<input type="hidden" name="email" id="email" value="<?php echo $my->email; ?>" />
<?php
}
?>

<tr>
<td class="key">留言</td>
<td><textarea name="title" id="title" style="width:100%; height:60px;"></textarea></td>
</tr>

<tr>
<td class="key">验证码</td>
<td>
<input type="text" name="captcha" id="captcha" style="width:60px;" maxlength="4" /> &nbsp; 
<img src="./?controller=captcha&task=message" align="absmiddle" alt="点击刷新" style="cursor:pointer" id="captcha-img" onClick="this.src='./?controller=captcha&task=message&_='+Math.random();" /> &nbsp; 
<a href="javascript:;" onclick="javascript:document.getElementById('captcha-img').src='./?controller=captcha&task=message&_='+Math.random();">看不清楚，刷新</a>
</td>
</tr>

<tr>
<td class="key"></td>
<td>
<input type="submit" id="submit" value="提交" />
</td>
</tr>
</table>
</form>

<div id="message-msg"></div>


</div>

		<?php
	}		
		

}
?>